//
//  TimelineTest.mm
//  TwitPlane
//
//  Created by kazuyuki takahashi on 11/09/09.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <gtest/gtest.h>
#import "TimeLine.h"
#import "TwitterEngine.h"
#import "Status.h"

class TimelineTest : public ::testing::Test {
protected:
    virtual void SetUp() {
        mPool = [[NSAutoreleasePool alloc] init];
        mTimeline = [[Timeline alloc] init];
        mEngine = [[TwitterEngine alloc] init];
        [mTimeline setTwitterEngine:mEngine];
    }
    
    virtual void TearDown() {
        [mEngine release];
        [mTimeline release];
        [mPool release];
    }
    
    Timeline *mTimeline;
    TwitterEngine *mEngine;
    NSAutoreleasePool *mPool;
};

TEST_F(TimelineTest, init) {
    EXPECT_TRUE(mTimeline);
    EXPECT_EQ(0, [mTimeline count]);
}

TEST_F(TimelineTest, receiveStatus) {
    Status *s0 = [[[Status alloc] initWithID:1] autorelease];
    [mEngine test_addStatus:s0];
    
    EXPECT_EQ(1, [mTimeline count]);
    EXPECT_TRUE([[mTimeline statusAtIndex:0] isEqual:s0]);
    
    //timeline内ではstatusは常にIDで降順ソートされている
    
    Status *s1 = [[[Status alloc] initWithID:5] autorelease];
    [mEngine test_addStatus:s1];
    EXPECT_EQ(2, [mTimeline count]);
    EXPECT_TRUE([[mTimeline statusAtIndex:0] isEqual:s1]);
    EXPECT_TRUE([[mTimeline statusAtIndex:1] isEqual:s0]);
    
    Status *s2 = [[[Status alloc] initWithID:100] autorelease];
    [mEngine test_addStatus:s2];
    EXPECT_EQ(3, [mTimeline count]);
    EXPECT_TRUE([[mTimeline statusAtIndex:0] isEqual:s2]);
    EXPECT_TRUE([[mTimeline statusAtIndex:1] isEqual:s1]);
    EXPECT_TRUE([[mTimeline statusAtIndex:2] isEqual:s0]);
    
    Status *s3 = [[[Status alloc] initWithID:50] autorelease];
    [mEngine test_addStatus:s3];
    EXPECT_EQ(4, [mTimeline count]);
    EXPECT_TRUE([[mTimeline statusAtIndex:0] isEqual:s2]);
    EXPECT_TRUE([[mTimeline statusAtIndex:1] isEqual:s3]);
    EXPECT_TRUE([[mTimeline statusAtIndex:2] isEqual:s1]);
    EXPECT_TRUE([[mTimeline statusAtIndex:3] isEqual:s0]);
}
